package com.esd.controller.csair;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.esd.csair.Csair;
import com.esd.csair.CsairImpl;
import com.esd.csair.UserFeedback;

@Controller
@RequestMapping(value = "cs")
public class CsSpecialController {

	private static Logger log = Logger.getLogger(CsSpecialController.class);
	
	/**
	 * 特殊旅客出行提示
	 * @return
	 */
	@RequestMapping(value = "specialpassenger", method = RequestMethod.GET)
	public ModelAndView specialpassenger(HttpSession session){
		log.info("=============================特殊旅客出行提示===============================");
//		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
//		Map<String, Object> map = webClient.specialpassenger();
		return new  ModelAndView("csair/specialpassengerdoc2");
	}

	/**
	 * 行动障碍旅客
	 * @return
	 */
	@RequestMapping(value = "mobilitydisorders" , method = RequestMethod.GET)
	public ModelAndView mobilitydisorders(HttpSession session){
		log.info("=============================行动障碍旅客===============================");
//		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
//		Map<String, Object> map = webClient.mobilitydisorders();
		return new ModelAndView("csair/mobilitydisorders2");
	}
	
	/**
	 * 听力或视力障碍旅客
	 * @return
	 */
	@RequestMapping(value = "visionhearingimpairment",method = RequestMethod.GET)
	public ModelAndView visionhearingimpairment(HttpSession session){
		log.info("=============================听力或视力障碍旅客===============================");
//		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
//		Map<String, Object> map = webClient.visionhearingimpairment();
		return new ModelAndView("csair/visionhearingimpairment2");
	}
	
	/**
	 * 跳转机票预订页面
	 * @return
	 */
	@RequestMapping(value = "ticketBooking",method = RequestMethod.GET)
	public String ticketBooking(HttpSession session){
		log.info("==================跳转机票预订页面=================");
		return "csair/cxbz_ticketBooking";
	}
	
	/**
	 * 跳转预订须知页面
	 * @return
	 */
	@RequestMapping(value = "bookingNotice",method = RequestMethod.GET)
	public String bookingNotice(HttpSession session){
		log.info("==================跳转预订须知页面=================");
		return "csair/cxbz_ticketBooking_bookingNotice";
	}
	/**
	 * 跳转预订须知列表页面
	 * @return
	 */
	@RequestMapping(value = "travelInfo",method = RequestMethod.GET)
	public String travelInfo(HttpSession session){
		log.info("==================跳转预订须知列表页面=================");
		return "csair/cxbz_ticketBooking_bookingNotice_TravelInfoLB";
	}
	
	/**
	 * 跳转服务协议列表页面
	 * @return
	 */
	@RequestMapping(value = "serviceAgreement",method = RequestMethod.GET)
	public String serviceAgreement(HttpSession session){
		log.info("==================跳转服务协议列表页面=================");
		return "csair/cxbz_ticketBooking_bookingNotice_serviceAgreementLB";
	}

	/**
	 * 点击链接进行内容加载
	 * @return
	 */
	@RequestMapping(value = "cxbz_clickA",method = RequestMethod.GET)
	public ModelAndView travelInfo_clickA(HttpSession session,HttpServletRequest request){
		log.info("=============================点击链接链接进行内容加载===============================");
		String href = request.getParameter("href");
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		Map<String, Object> map = webClient.cxbz_clickA(href);
		return new ModelAndView("csair/cxbz_Content",map);
	}
	/**
	 * 机票预订-各地服务点变更国家
	 * @return
	 */
	@RequestMapping(value = "countryChange",method = RequestMethod.GET)
	public ModelAndView countryChange(HttpSession session,HttpServletRequest request){
		log.info("=============================机票预订-各地服务点变更国家===============================");
		String country =  null;
		try {
			country = new String(request.getParameter("country").getBytes("ISO-8859-1"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		Map<String, Object> map = webClient.countryChange(country);
		return new ModelAndView("csair/loadPage",map);
	}
	
	/**
	 * 机票预订-各地服务点搜索
	 * @return
	 */
	@RequestMapping(value = "searchServicePoint",method = RequestMethod.GET)
	public ModelAndView searchServicePoint(HttpSession session,HttpServletRequest request){
		log.info("=============================机票预订-各地服务点搜索===============================");
		String country =  null;
		String city =  null;
		try {
			country = new String(request.getParameter("country").getBytes("ISO-8859-1"), "UTF-8");
			city = new String(request.getParameter("city").getBytes("ISO-8859-1"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		Map<String, Object> map = webClient.searchServicePoint(country,city);
		return new ModelAndView("csair/loadPage",map);
	}
	
	/**
	 * 机票预订-南航授权代理商搜索
	 * @return
	 */
	@RequestMapping(value = "searchAgent",method = RequestMethod.GET)
	public ModelAndView searchAgent(HttpSession session,HttpServletRequest request){
		log.info("=============================机票预订-南航授权代理商搜索===============================");
		String cityValue =  null;
		String selValue =  null;
		String selectValue =  null;
		try {
			cityValue = new String(request.getParameter("cityValue").getBytes("ISO-8859-1"), "UTF-8");
			selValue = new String(request.getParameter("selValue").getBytes("ISO-8859-1"), "UTF-8");
			selectValue = new String(request.getParameter("selectValue").getBytes("ISO-8859-1"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		Map<String, Object> map = webClient.searchAgent(cityValue,selValue,selectValue);
		return new ModelAndView("csair/loadPage",map);
	}
	
	/**
	 * 跳转出行准备页面
	 * @return
	 */
	@RequestMapping(value = "travelPreparation",method = RequestMethod.GET)
	public String travelPreparation(HttpSession session){
		log.info("==================跳转出行准备页面=================");
		return "csair/cxbz_travelPreparation";
	}
	/**
	 * 跳转办理值机页面
	 * @return
	 */
	@RequestMapping(value = "goOnDuty",method = RequestMethod.GET)
	public String goOnDuty(HttpSession session){
		log.info("==================跳转办理值机页面=================");
		return "csair/cxbz_goOnDuty";
	}
	/**
	 * 跳转行李服务页面
	 * @return
	 */
	@RequestMapping(value = "luggageService",method = RequestMethod.GET)
	public String luggageService(HttpSession session){
		log.info("==================跳转行李服务页面=================");
		return "csair/cxbz_luggageService";
	}
	/**
	 * 跳转特殊协助页面
	 * @return
	 */
	@RequestMapping(value = "special",method = RequestMethod.GET)
	public String special(HttpSession session){
		log.info("==================跳转特殊协助页面=================");
		return "csair/cxbz_special";
	}
	/**
	 * 跳转机场服务页面
	 * @return
	 */
	@RequestMapping(value = "airportService",method = RequestMethod.GET)
	public String airportService(HttpSession session){
		log.info("==================跳转机场服务页面=================");
		return "csair/cxbz_airportService";
	}
	
	/**
	 * 机场服务-电子商务柜台城市变更
	 * @return
	 */
	@RequestMapping(value = "airportServiceCityChange",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> airportServiceCityChange(HttpSession session,HttpServletRequest request){
		log.info("=============================机场服务-电子商务柜台城市变更===============================");
//		String city =  null;
//		try {
//			city = new String(request.getParameter("city").getBytes("ISO-8859-1"), "UTF-8");
//		} catch (UnsupportedEncodingException e) {
//			e.printStackTrace();
//		}
		String city = request.getParameter("city");
		try {
			city = URLDecoder.decode(city,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		Map<String, Object> map = webClient.airportServiceCityChange(city);
		return map;
	}
	
	/**
	 * 跳转中转服务页面
	 * @return
	 */
	@RequestMapping(value = "transfers",method = RequestMethod.GET)
	public String transfers(HttpSession session){
		log.info("==================跳转中转服务页面=================");
		return "csair/cxbz_transfers";
	}
	/**
	 * 跳转机上服务页面
	 * @return
	 */
	@RequestMapping(value = "flightService",method = RequestMethod.GET)
	public String flightService(HttpSession session){
		log.info("==================跳转机上服务页面=================");
		return "csair/cxbz_flightService";
	}
	/**
	 * 跳转体验中心页面
	 * @return
	 */
	@RequestMapping(value = "experienceCenter",method = RequestMethod.GET)
	public String experienceCenter(HttpSession session){
		log.info("==================跳转体验中心页面=================");
		return "csair/cxbz_experienceCenter";
	}
	/**
	 * 跳转常见问题页面
	 * @return
	 */
	@RequestMapping(value = "frequentlyAskedQuestions",method = RequestMethod.GET)
	public String frequentlyAskedQuestions(HttpSession session){
		log.info("==================跳转体验中心页面=================");
		return "csair/cxbz_frequentlyAskedQuestions";
	}
	/**
	 * 跳转常见问题-航班信息列表页面
	 * @return
	 */
	@RequestMapping(value = "faqFlight",method = RequestMethod.GET)
	public String faqFlight(HttpSession session){
		log.info("==================跳转常见问题-航班信息列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqFlightLB";
	}
	/**
	 * 跳转常见问题-网上预订服务列表页面
	 * @return
	 */
	@RequestMapping(value = "faqReserve",method = RequestMethod.GET)
	public String faqReserve(HttpSession session){
		log.info("==================跳转常见问题-网上预订服务列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqReserveLB";
	}
	/**
	 * 跳转常见问题-办理乘机手续列表页面
	 * @return
	 */
	@RequestMapping(value = "faqCheckIn",method = RequestMethod.GET)
	public String faqCheckIn(HttpSession session){
		log.info("==================跳转常见问题-办理乘机手续列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqCheckInLB";
	}
	/**
	 * 跳转常见问题-机上服务列表页面
	 * @return
	 */
	@RequestMapping(value = "faqInFlight",method = RequestMethod.GET)
	public String faqInFlight(HttpSession session){
		log.info("==================跳转常见问题-机上服务列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqInFlightLB";
	}
	/**
	 * 跳转常见问题-行李服务列表页面
	 * @return
	 */
	@RequestMapping(value = "faqBaggage",method = RequestMethod.GET)
	public String faqBaggage(HttpSession session){
		log.info("==================跳转常见问题-行李服务列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqBaggageLB";
	}
	/**
	 * 跳转常见问题-机场服务列表页面
	 * @return
	 */
	@RequestMapping(value = "faqAirport",method = RequestMethod.GET)
	public String faqAirport(HttpSession session){
		log.info("==================跳转常见问题-机场服务列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqAirportLB";
	}
	/**
	 * 跳转常见问题-移动服务列表页面
	 * @return
	 */
	@RequestMapping(value = "faqMobileService",method = RequestMethod.GET)
	public String faqMobileService(HttpSession session){
		log.info("==================跳转常见问题-移动服务列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqMobileServiceLB";
	}
	/**
	 * 跳转常见问题-特殊旅客服务列表页面
	 * @return
	 */
	@RequestMapping(value = "faqSpecialAssistance",method = RequestMethod.GET)
	public String faqSpecialAssistance(HttpSession session){
		log.info("==================跳转常见问题-特殊旅客服务列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqSpecialAssistanceLB";
	}
	/**
	 * 跳转常见问题-企业商旅列表页面
	 * @return
	 */
	@RequestMapping(value = "faqBusiness",method = RequestMethod.GET)
	public String faqBusiness(HttpSession session){
		log.info("==================跳转常见问题-企业商旅列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqBusinessLB";
	}
	/**
	 * 跳转常见问题-明珠俱乐部列表页面
	 * @return
	 */
	@RequestMapping(value = "faqClub",method = RequestMethod.GET)
	public String faqClub(HttpSession session){
		log.info("==================跳转常见问题-明珠俱乐部列表页面=================");
		return "csair/cxbz_frequentlyAskedQuestions_faqClubLB";
	}
	/**
	 * 跳转客户服务页面
	 * @return
	 */
	@RequestMapping(value = "customerService",method = RequestMethod.GET)
	public String customerService(HttpSession session){
		log.info("==================跳转客户服务页面=================");
		return "csair/customerService";
	}
	/**
	 * 跳转客户服务-联系我们页面
	 * @return
	 */
	@RequestMapping(value = "contactUs",method = RequestMethod.GET)
	public String contactUs(HttpSession session){
		log.info("==================跳转客户服务-联系我们页面=================");
		return "csair/customerService_contactUs";
	}
	/**
	 * 跳转客户服务-用户反馈页面
	 * @return
	 */
	@RequestMapping(value = "userFeedback",method = RequestMethod.GET)
	public String userFeedback(HttpSession session){
		log.info("==================跳转客户服务-联系我们页面=================");
		return "csair/customerService_userFeedback";
	}
	
	/**
	 * 客户服务-用户反馈页面加载
	 * @return
	 */
	@RequestMapping(value = "loadUserFeedback",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> loadUserFeedback(HttpSession session){
		log.info("==================客户服务-联系我们页面加载=================");
		Map<String, Object> map = new HashMap<String,Object>();
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		map = webClient.loadUserFeedback();
		return map;
	}
	/**
	 * 客户服务-用户反馈页面发送验证码
	 * @return
	 */
	@RequestMapping(value = "userFeedback_yzm",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> userFeedback_yzm(HttpSession session,HttpServletRequest request){
		log.info("==================客户服务-联系我们页面发送验证码=================");
		String mobile = request.getParameter("mobile");
		try {
			mobile = URLDecoder.decode(mobile,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Map<String, Object> map = new HashMap<String,Object>();
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		map = webClient.userFeedback_yzm(mobile);
		return map;
	}
	/**
	 * 客户服务-用户反馈页面提交反馈
	 * @return
	 */
	@RequestMapping(value = "userFeedback_submit",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> userFeedback_submit(HttpSession session,HttpServletRequest request){
		log.info("==================客户服务-联系我们页面提交反馈=================");
		UserFeedback userFeedback = new UserFeedback();
		String category = request.getParameter("category");
		String businessType = request.getParameter("businessType");
		String handChannel = request.getParameter("handChannel");
		String name = request.getParameter("name");
		String content = request.getParameter("content");
		String username = request.getParameter("username");
		String mobile = request.getParameter("mobile");
		String mcode = request.getParameter("mcode");
		String email = request.getParameter("email");
		try {
			category = URLDecoder.decode(category,"UTF-8");
			businessType = URLDecoder.decode(businessType,"UTF-8");
			handChannel = URLDecoder.decode(handChannel,"UTF-8");
			name = URLDecoder.decode(name,"UTF-8");
			content = URLDecoder.decode(content,"UTF-8");
			username = URLDecoder.decode(username,"UTF-8");
			mobile = URLDecoder.decode(mobile,"UTF-8");
			mcode = URLDecoder.decode(mcode,"UTF-8");
			email = URLDecoder.decode(email,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		userFeedback.setCategory(category);
		userFeedback.setBusinessType(businessType);
		userFeedback.setHandChannel(handChannel);
		userFeedback.setName(name);
		userFeedback.setContent(content);
		userFeedback.setUsername(username);
		userFeedback.setMobile(mobile);
		userFeedback.setMcode(mcode);
		userFeedback.setEmail(email);
		Map<String, Object> map = new HashMap<String,Object>();
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		map = webClient.userFeedback_submit(userFeedback);
		return map;
	}
	/**
	 * 关于南航-投资者关系-电邮订阅中心提交
	 * @return
	 */
	@RequestMapping(value = "submitEmail",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> submitEmail(HttpSession session,HttpServletRequest request){
		log.info("==================关于南航-投资者关系-电邮订阅中心提交=================");
		String emailNo = request.getParameter("emailNo");
		String m_status = request.getParameter("m_status");
		String firstName = request.getParameter("firstName");
		String lastName = request.getParameter("lastName");
		String vocation = request.getParameter("vocation");
		String country = request.getParameter("country");
		try {
			emailNo = URLDecoder.decode(emailNo,"UTF-8");
			m_status = URLDecoder.decode(m_status,"UTF-8");
			firstName = URLDecoder.decode(firstName,"UTF-8");
			lastName = URLDecoder.decode(lastName,"UTF-8");
			vocation = URLDecoder.decode(vocation,"UTF-8");
			country = URLDecoder.decode(country,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Map<String, Object> map = new HashMap<String,Object>();
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		map = webClient.submitEmail(emailNo,m_status,firstName,lastName,vocation,country);
		return map;
	}
	
	/**
	 * 跳转关于南航页面
	 * @return
	 */
	@RequestMapping(value = "aboutCsair",method = RequestMethod.GET)
	public String aboutCsair(HttpSession session){
		log.info("==================跳转关于南航页面=================");
		return "csair/aboutCsair";
	}
	/**
	 * 跳转关于南航-投资者关系页面
	 * @return
	 */
	@RequestMapping(value = "investor",method = RequestMethod.GET)
	public String investor(HttpSession session){
		log.info("==================跳转关于南航-投资者关系页面=================");
		return "csair/aboutCsair_investor";
	}
	
	/**
	 * 关于南航-投资者关系-列表页号选择
	 * @return
	 */
	@RequestMapping(value = "csairPagesClick",method = RequestMethod.GET)
	public ModelAndView csairPagesClick(HttpSession session,HttpServletRequest request){
		log.info("=============================关于南航-投资者关系-列表页号选择===============================");
		String href =  null;
		String page =  null;
		try {
			href = new String(request.getParameter("href").getBytes("ISO-8859-1"), "UTF-8");
			page = new String(request.getParameter("page").getBytes("ISO-8859-1"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		Map<String, Object> map = webClient.csairPagesClick(href,page);
		return new ModelAndView("csair/loadPage",map);
	}
	/**
	 * 关于南航-投资者关系-财务总览表格选择
	 * @return
	 */
	@RequestMapping(value = "tableChooseClick",method = RequestMethod.GET)
	public ModelAndView tableChooseClick(HttpSession session,HttpServletRequest request){
		log.info("=============================关于南航-投资者关系-财务总览表格选择===============================");
		String data_href =  null;
		try {
			data_href = new String(request.getParameter("data_href").getBytes("ISO-8859-1"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Csair webClient = (CsairImpl) session.getAttribute(Csair.WEBCLIENT);
		Map<String, Object> map = webClient.tableChooseClick(data_href);
		return new ModelAndView("csair/loadPage",map);
	}
}
